package com.gyhoo.firstbootdemo.controller;

import org.springframework.stereotype.Controller;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;

import javax.servlet.http.HttpSession;
import java.util.Map;

@Controller
public class LoginController {
    @RequestMapping("/login")
    public String doLogin(@RequestParam String username,
                          @RequestParam String password,
                          Map map,
                          HttpSession session){
        if(!StringUtils.isEmpty(username) && "qwe".equals(password)){
            session.setAttribute("username",username);
            return "redirect:/main.html";
        }else {
            map.put("msg","账号或密码错误！");
        }

        return "login";
    }

    @RequestMapping("/signOut")
    public String signOut(HttpSession session){
        session.invalidate();
        return "redirect:/";
    }

}
